package com.xiaoshuidi.cloud.module.rooms.enums;

import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * @Author Feng
 * @date 2023/5/31
 */
@Getter
@AllArgsConstructor
public enum EstimateStatus {


    TO_BE_CALCULATED("1", "待测算"),

    CALCULATED("2", "已测算");

    private String code;
    private String name;

    public static String getCodeByName(String name) {
        if (StrUtil.isEmpty(name)) {
            return null;
        }
        Optional<EstimateStatus> find = Arrays.stream(EstimateStatus.values()).filter(s -> s.getName().equals(name)).findFirst();
        if (find.isPresent()) {
            return find.get().getCode();
        }
        return null;
    }

    public static String getNameByCode(String code) {
        if (StrUtil.isEmpty(code)) {
            return null;
        }
        Optional<EstimateStatus> find = Arrays.stream(EstimateStatus.values()).filter(s -> s.getCode().equals(code)).findFirst();
        if (find.isPresent()) {
            return find.get().getName();
        }
        return null;
    }
}
